package com.yetianhua.consistencysession.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author yetianhua
 * @description: 登陆拦截器
 * @create: 2021-07-25 11:47
 */
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String username = (String) request.getSession().getAttribute("username");
        if(username == null){
            response.sendRedirect("toLogin");
            return false;
        } else {
            return true;
        }
    }


}
